if (typeof inweo.utils.dnd == "undefined") {
	inweo.utils.dnd = new Class({
		selected: [],
		initialize: function() {
			if (inweo.get("inweo.utils.dnd") != true) {
				inweo.set("inweo.utils.dnd", true);
				inweo.utils.dnd = this;

				inweo.utils.dnd.widget = new Element("div");
				inweo.utils.dnd.widget.addClass("widgetDnd");
				inweo.utils.dnd.widget.injectInside(document.body);

				inweo.utils.dnd.img = new Element("img");
				inweo.utils.dnd.img.setProperty("src", inweo.get("path") + "skin/images/transparent.png");
				inweo.utils.dnd.img.injectInside(inweo.utils.dnd.widget);

				inweo.utils.dnd.span = new Element("span");
				inweo.utils.dnd.span.injectInside(inweo.utils.dnd.widget);

				inweo.utils.dnd.container = new Element("div");
				inweo.utils.dnd.container.injectInside(inweo.utils.dnd.widget);
			}
			return inweo.utils.dnd;
		},
		text: function(string) {
			if (string != null) {
				inweo.utils.dnd.span.setText(string);
			} else {
				return inweo.utils.dnd.span.getText();
			}
		},
		image: function(src) {
			if (src != null) {
				inweo.utils.dnd.img.setProperty("src", src);
				inweo.utils.dnd.img.setStyle("display", "block");
			} else {
				return inweo.utils.dnd.img.getProperty("src");
			}
		}
	});
	new inweo.utils.dnd();
	inweo.utils.dnd.dragSource = new Class({
		__data: [],
		__onStart: function() {},
		__onDrag: function() {},
		__onComplete: function() {},
		initialize: function(object) {
			this.widget = object.widget;
		},
		data: function(type, data) {
			this.__data.type = type;
			this.__data.data = data;
		},
		onStart: function(func) {
			this.__onStart = func;
		},
		onDrag: function(func) {
			this.__onDrag = func;
		},
		onComplete: function(func) {
			this.__onComplete = func;
		},
		start: function() {
			var self = this;
			var mouseEvent = new inweo.core.event(this.widget);
			mouseEvent.addEvent("mousedown", function(event) {
				if (event.control != true) {
					document.getElements(".widgetDragableSelected").each(function(selected) {
						selected.removeClass("widgetDragableSelected");
					});
					inweo.utils.dnd.selected = [];
				}
				if (self.widget.hasClass("widgetDragableSelected")) {
					return;
				}
				inweo.utils.dnd.selected.push(self.__data);
				self.widget.addClass("widgetDragableSelected");
				self.dndEvent = inweo.utils.dnd.widget.makeDraggable({
					droppables: $$(".widgetDroppable"),
					onStart: function() {
						self.__onStart.call(inweo.utils.dnd, event);
						inweo.utils.dnd.widget.setStyle("display", "block");
						inweo.utils.dnd.widget.setStyle("top", event.page.x + 10);
						inweo.utils.dnd.widget.setStyle("left", event.page.y + 10);
					},
					onDrag: function() {
						self.__onDrag.call(inweo.utils.dnd, event);
						inweo.utils.dnd.widget.setStyle("top", self.dndEvent.mouse.now.y + 10);
						inweo.utils.dnd.widget.setStyle("left", self.dndEvent.mouse.now.x + 10);
					},
					onComplete: function() {
						self.__onComplete.call(inweo.utils.dnd, event);
						inweo.utils.dnd.widget.setStyle("display", "none");
						inweo.utils.dnd.selected = [];
					}
				});
				self.dndEvent.start(event);
			});
			self.widget.addClass("widgetDraggable");
		},
		stop: function() {
			this.dndEvent.stop(event);
		}
	});
	inweo.utils.dnd.dropTarget = new Class({
		id: null,
		__onOver: function() {},
		__onOut: function() {},
		__onDrop: function() {},
		_type: null,
		initialize: function(object) {
			this.widget = object.widget;
		},
		accept: function(type) {
			this._type = type;
		},
		onOver: function(func) {
			this.__onOver = func;
		},
		onOut: function(func) {
			this.__onOut = func;
		},
		onDrop: function(func) {
			this.__onDrop = func;
		},
		start: function() {
			var self = this;
			this.widget.addClass("widgetDroppable");
			this.widget.addEvents({
				"over": function(draggedElement, event) {
					if ((self._type != null) && !self._type.contains(inweo.utils.dnd.selected[0].type)) {
						document.body.addClass("widgetNoDrop");
					}
					document.body.addClass("widgetDrop");
					inweo.utils.dnd.type = inweo.utils.dnd.selected[0];
					self.__onOver.call(inweo.utils.dnd, event);
				},
				"leave": function(draggedElement, event) {
					document.body.removeClass("widgetDrop");
					document.body.removeClass("widgetNoDrop");
					inweo.utils.dnd.type = inweo.utils.dnd.selected[0];
					self.__onOut.call(inweo.utils.dnd, event);
				},
				"drop": function(draggedElement, event) {
					document.body.removeClass("widgetDrop");
					document.body.removeClass("widgetNoDrop");
					inweo.utils.dnd.type = inweo.utils.dnd.selected[0];
					self.__onDrop.call(inweo.utils.dnd, event);
				}
			});
		},
		stop: function() {
			
		}
	});
}